package com.yuuzy.mapper;

import com.yuuzy.annotation.AutoFill;
import com.yuuzy.entity.User;
import com.yuuzy.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


@Mapper
public interface UserMapper {

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from user where username = #{username}")
    User getByUsername(String username);

    /**
     * 插入用户数据
     *
     * @param user
     */
    @Insert("insert into user (username,password,role,create_time,update_time) values " +
            "(#{username},#{password},#{role},#{createTime},#{updateTime})")
    @AutoFill(OperationType.INSERT)
    void insert(User user);


    @Update("update user set password = #{password} ,update_time = #{updateTime} " +
            "where username = #{username}")
    @AutoFill(OperationType.UPDATE)
    void updatePassword(User user);
}
